package cn.iocoder.yudao.module.system.dal.mysql.gugu;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.gugu.ProvinceScoreDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 历年高考省录取分数线数据 Mapper
 */
@Mapper
public interface ProvinceScoreMapper extends BaseMapperX<ProvinceScoreDO> {

    /**
     * 根据省份、年份和学科分类查询省录取分数线数据
     *
     * @param province 省份
     * @param year 年份
     * @param category 学科分类
     * @return 省录取分数线数据列表
     */
    default List<ProvinceScoreDO> selectByProvinceYearAndCategory(String province, Integer year, String category) {
        return selectList(new LambdaQueryWrapperX<ProvinceScoreDO>()
                .eqIfPresent(ProvinceScoreDO::getProvince, province)
                .eqIfPresent(ProvinceScoreDO::getYear, year)
                .eqIfPresent(ProvinceScoreDO::getCategory, category)
                .orderByDesc(ProvinceScoreDO::getYear)
                .orderByAsc(ProvinceScoreDO::getProvince)
                .orderByAsc(ProvinceScoreDO::getCategory)
                .orderByAsc(ProvinceScoreDO::getScoreBatch));
    }

    /**
     * 根据省份查询省录取分数线数据
     *
     * @param province 省份
     * @return 省录取分数线数据列表
     */
    default List<ProvinceScoreDO> selectByProvince(String province) {
        return selectList(new LambdaQueryWrapperX<ProvinceScoreDO>()
                .eq(ProvinceScoreDO::getProvince, province)
                .orderByDesc(ProvinceScoreDO::getYear)
                .orderByAsc(ProvinceScoreDO::getCategory)
                .orderByAsc(ProvinceScoreDO::getScoreBatch));
    }

    /**
     * 根据年份查询省录取分数线数据
     *
     * @param year 年份
     * @return 省录取分数线数据列表
     */
    default List<ProvinceScoreDO> selectByYear(Integer year) {
        return selectList(new LambdaQueryWrapperX<ProvinceScoreDO>()
                .eq(ProvinceScoreDO::getYear, year)
                .orderByAsc(ProvinceScoreDO::getProvince)
                .orderByAsc(ProvinceScoreDO::getCategory)
                .orderByAsc(ProvinceScoreDO::getScoreBatch));
    }

    /**
     * 根据学科分类查询省录取分数线数据
     *
     * @param category 学科分类
     * @return 省录取分数线数据列表
     */
    default List<ProvinceScoreDO> selectByCategory(String category) {
        return selectList(new LambdaQueryWrapperX<ProvinceScoreDO>()
                .eq(ProvinceScoreDO::getCategory, category)
                .orderByDesc(ProvinceScoreDO::getYear)
                .orderByAsc(ProvinceScoreDO::getProvince)
                .orderByAsc(ProvinceScoreDO::getScoreBatch));
    }

    /**
     * 检查指定条件的数据是否已存在
     *
     * @param province 省份
     * @param year 年份
     * @param category 学科分类
     * @param scoreBatch 录取批次
     * @return 是否存在
     */
    default boolean existsByProvinceYearCategoryAndBatch(String province, Integer year, String category, String scoreBatch) {
        return selectCount(new LambdaQueryWrapperX<ProvinceScoreDO>()
                .eq(ProvinceScoreDO::getProvince, province)
                .eq(ProvinceScoreDO::getYear, year)
                .eq(ProvinceScoreDO::getCategory, category)
                .eq(ProvinceScoreDO::getScoreBatch, scoreBatch)) > 0;
    }

    /**
     * 分页查询省录取分数线数据
     *
     * @param reqVO 查询条件
     * @return 分页结果
     */
    default PageResult<ProvinceScoreDO> selectPage(cn.iocoder.yudao.module.system.controller.admin.gugu.vo.ProvinceScorePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProvinceScoreDO>()
                .likeIfPresent(ProvinceScoreDO::getProvince, reqVO.getProvince())
                .eqIfPresent(ProvinceScoreDO::getYear, reqVO.getYear())
                .eqIfPresent(ProvinceScoreDO::getCategory, reqVO.getCategory())
                .eqIfPresent(ProvinceScoreDO::getScoreBatch, reqVO.getScoreBatch())
                .eqIfPresent(ProvinceScoreDO::getScore, reqVO.getScore())
                .likeIfPresent(ProvinceScoreDO::getSpecialName, reqVO.getSpecialName())
                .betweenIfPresent(ProvinceScoreDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProvinceScoreDO::getYear)
                .orderByAsc(ProvinceScoreDO::getProvince)
                .orderByAsc(ProvinceScoreDO::getCategory)
                .orderByAsc(ProvinceScoreDO::getScoreBatch));
    }

    /**
     * 根据省份、年份、学科分类和录取批次删除数据
     *
     * @param province 省份
     * @param year 年份
     * @param category 学科分类
     * @param scoreBatch 录取批次
     * @return 删除的记录数
     */
    default int deleteByProvinceYearCategoryAndBatch(String province, Integer year, String category, String scoreBatch) {
        return delete(new LambdaQueryWrapperX<ProvinceScoreDO>()
                .eq(ProvinceScoreDO::getProvince, province)
                .eq(ProvinceScoreDO::getYear, year)
                .eq(ProvinceScoreDO::getCategory, category)
                .eq(ProvinceScoreDO::getScoreBatch, scoreBatch));
    }

    /**
     * 根据年份删除数据
     *
     * @param year 年份
     * @return 删除的记录数
     */
    default int deleteByYear(Integer year) {
        return delete(new LambdaQueryWrapperX<ProvinceScoreDO>()
                .eq(ProvinceScoreDO::getYear, year));
    }
}
